# !/usr/bin/python
# -*- coding: utf-8 -*-
"""
@FileName:  base.py
@Time    :  2021-12-30 0:41
@Author  :  Alan_1999
@Version :  1.0
@License :  (C)Copyright 2021-2022
@Desc    :  
"""
import pymysql


class MySQLHelper:
    def __init__(self):
        try:
            self.conn = pymysql.connect(host="localhost", user="root", password="lales1999", port=3306,
                                        database="book_shop")
            # print("conn success")
        except Exception as e:
            print("conn error:", e)

    def executeForUCD(self, sql, params):
        self.cuser = self.conn.cursor();
        i = self.cuser.execute(sql, params)
        self.conn.commit();
        return i

    def executeForSelectOne(self, sql, params):
        self.cursor = self.conn.cursor()
        self.cursor.execute(sql, params)
        rs = self.cursor.fetchone()

        return rs

    def executeForSelectAll(self, sql, parms):
        self.cursor = self.conn.cursor()
        self.cursor.execute(sql, parms)
        rs = self.cursor.fetchall()
        return rs

    def close(self):
        try:
            self.conn.close()
            self.cursor.close()
        except Exception as e:
            print("error=", e)
        finally:
            print("finally")
